<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

$tblname = $_REQUEST["tblname"];

if ($tblname == "")
    $tblname = "tbl_pet";
$db = NEW myDBS();

switch ($tblname) {
    case "tbl_pet":
        $sql = "SELECT DISTINCT id, tt, receiver "
                . " FROM tbl_pet "
                . " WHERE approved_status = 'อนุมัติ' "
            . " AND tt <> 0";

        break;

    case "tbl_petition":

        $sql = "SELECT DISTINCT petition_id AS id, (inpValues * WithholdingTax) / 100 AS tt, company_name AS receiver "
                . " FROM tbl_petition "
                . " WHERE approved_status = 'อนุมัติ' ";

        break;

    case "tbl_salary":
        $sql = " SELECT salary_id AS id, tax1 AS tt, tbl_init.card_id AS receiver "
                . " FROM  tbl_salary , tbl_init "
                . " WHERE approved_status =  'อนุมัติ' "
                . " AND tbl_salary.id = tbl_init.card_id"
                . " AND tax1 <> 0";

        break;

    default:

         $sql = "SELECT DISTINCT id, tt, receiver "
                . " FROM tbl_pet "
                . " WHERE approved_status = 'อนุมัติ' ";

        break;
}
//
//$db = NEW myDBS();
//
//$sql = "SELECT DISTINCT tt, receiver "
//        . " FROM tbl_pet "
//        . " WHERE approved_status = 'อนุมัติ' "
//        . " UNION "
//        . "SELECT DISTINCT (inpValues * WithholdingTax) / 100 AS tt, company_name AS receiver "
//        . " FROM tbl_petition "
//        . " WHERE approved_status = 'อนุมัติ' "
//        . " UNION "
//        . " SELECT tax1 AS tt, tbl_init.card_id AS receiver "
//        . " FROM  tbl_salary , tbl_init "
//        . " WHERE approved_status =  'อนุมัติ' "
//        . " AND tbl_salary.id = tbl_init.card_id"
//        . " AND tax1 <> 0";

//echo $sql;
$result = $db->runSQL($sql);
?>

<script type="text/javascript">
    $(document).ready(function() {
        $('#petition').dataTable();
        
        $("#tblname").change(function() {
            //alert($(this).val());
            window.location.href = "index.php?pages=tax1&tblname=" + $(this).val();
        });

    });

//    function print_tax() {
//
//    }
</script>

<div class="control-group">
    <div class="controls-row">
        <select id="tblname" name="tblname" >
            <option value="">เลือก...</option>
            <option value="tbl_pet" <?php echo ($tblname == "tbl_pet") ? "selected" : ""; ?>>อื่นๆ</option>
            <option value="tbl_petition" <?php echo ($tblname == "tbl_petition") ? "selected" : ""; ?>>โครงการ</option>
            <option value="tbl_salary" <?php echo ($tblname == "tbl_salary") ? "selected" : ""; ?>>เงินเดือน</option>
            <!--<option value="tbl_welfare" <?php // echo ($tblname == "tbl_welfare") ? "selected" : "";      ?>>สวัสดิการ</option>-->
        </select>
        <!--<a href="javascript:printCheque()" class=" btn btn-primary" target="_blank"><i class="icon-print icon-white"></i> บันทึกเช็ค</a>-->
    </div>
</div>

<table id="petition" class="table table-bordered table-hover" width="100%" >
    <caption><br></caption>
    <thead>
        <tr>
            <th>#</th>
            <th>ผู้เสียภาษี</th>
            <th>จำนวนเงิน</th>
            <th>action</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $i = 1;
        while ($rows = $db->fetch_object($result)) {
            ?>
            <tr>
                <td>&nbsp;<?php echo $i; ?></td>
                <td>&nbsp;
                    <?php
                    if (is_numeric($rows->receiver)) {
                        echo get_name_person($rows->receiver);
                    } else {
                        echo $rows->receiver;
                    }
                    ?>
                </td>
                <td><p class="text-right">&nbsp;<?php echo number_format($rows->tt, 2); ?></p></td>
                <td><p class="text-center"><a href="tax1_print.php?id=<?php echo $rows->id; ?>&tblname=<?php echo $tblname; ?>" target="_blank"><i class="icon-print"></i></a></p></td>

            </tr>
            <?php
            $i++;
        }
        ?>
    </tbody>
</table>

